package QuanLyHoaDon;

import KetNoiSQL.KetNoiSQL;
import QuanLyDatHang.DatHang;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

public class HoaDon {

    private int maHoaDon;
    private String loaiHoaDon;
    private int maKhachHang;
    private String tenKhachHang;
    private String diaChi;
    private String ngayTao;
    private String thoiHan;
    private float thue;
    private String tinhTrang;
    private int maThuoc;
    private String tenThuoc;
    private float gia;
    private int soLuong;
    private float tien;// tính tiền

    public int getMaHoaDon() {
        return maHoaDon;
    }

    public void setMaHoaDon(int maHoaDon) {
        this.maHoaDon = maHoaDon;
    }

    public String getLoaiHoaDon() {
        return loaiHoaDon;
    }

    public void setLoaiHoaDon(String loaiHoaDon) {
        this.loaiHoaDon = loaiHoaDon;
    }

    public int getMaKhachHang() {
        return maKhachHang;
    }

    public void setMaKhachHang(int maKhachHang) {
        this.maKhachHang = maKhachHang;
    }

    public String getTenKhachHang() {
        return tenKhachHang;
    }

    public String getDiaChi() {
        return diaChi;
    }

    public void setDiaChi(String diaChi) {
        this.diaChi = diaChi;
    }

    public void setTenKhachHang(String tenKhachHang) {
        this.tenKhachHang = tenKhachHang;
    }

    public String getNgayTao() {
        return ngayTao;
    }

    public void setNgayTao(String ngayTao) {
        this.ngayTao = ngayTao;
    }

    public String getThoiHan() {
        return thoiHan;
    }

    public void setThoiHan(String thoiHan) {
        this.thoiHan = thoiHan;
    }

    public float getThue() {
        return thue;
    }

    public void setThue(float thue) {
        this.thue = thue;
    }

    public String getTinhTrang() {
        return tinhTrang;
    }

    public void setTinhTrang(String tinhTrang) {
        this.tinhTrang = tinhTrang;
    }

    public int getMaThuoc() {
        return maThuoc;
    }

    public void setMaThuoc(int maThuoc) {
        this.maThuoc = maThuoc;
    }

    public String getTenThuoc() {
        return tenThuoc;
    }

    public void setTenThuoc(String tenThuoc) {
        this.tenThuoc = tenThuoc;
    }

    public int getSoLuong() {
        return soLuong;
    }

    public void setSoLuong(int soLuong) {
        this.soLuong = soLuong;
    }

    public float getGia() {
        return gia;
    }

    public void setGia(float gia) {
        this.gia = gia;
    }

    public float getTien() {
        return tien;
    }

    public void setTien(float tien) {
        this.tien = tien;
    }

    //Xem danh sách Hoa Đơn
    public static Vector xemDSHoaDon() throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan("spXemDanhSachHoaDon");
            while (rs.next()) {
                HoaDon xHD = new HoaDon();
                xHD.maHoaDon = rs.getInt(1);
                xHD.loaiHoaDon = rs.getString(2);
                xHD.tenKhachHang = rs.getString(3);
                xHD.tenThuoc = rs.getString(4);
                xHD.diaChi = rs.getString(5);
                xHD.ngayTao = rs.getString(6);
                xHD.thoiHan = rs.getString(7);
                xHD.thue = rs.getFloat(8);
                xHD.gia = rs.getFloat(9);
                xHD.tinhTrang = rs.getString(10);

                v.add(xHD);
            }
        } catch (SQLException ex) {
        }
        return v;
    }

    //Xem hóa đơn
    public static Vector xemHoaDon() throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan("spXemHoaDon");
            while (rs.next()) {
                HoaDon xHD = new HoaDon();
                xHD.maHoaDon = rs.getInt(1);
                xHD.loaiHoaDon = rs.getString(2);
                xHD.maKhachHang = rs.getInt(3);
                xHD.tenKhachHang = rs.getString(4);
                xHD.ngayTao = rs.getString(5);
                xHD.thoiHan = rs.getString(6);
                xHD.thue = rs.getFloat(7);
                xHD.tinhTrang = rs.getString(8);

                v.add(xHD);
            }
        } catch (SQLException ex) {
        }
        return v;
    }

    //Thêm hóa đơn
    public static int themHoaDon(HoaDon hd) throws SQLException {
        int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(hd.loaiHoaDon);
            dsThamSo.add(hd.maKhachHang);
            dsThamSo.add(hd.ngayTao);
            dsThamSo.add(hd.thoiHan);
            dsThamSo.add(hd.thue);
            dsThamSo.add(hd.tinhTrang);
            i = KetNoiSQL.thucHienCapNhat("spThemHoaDon", dsThamSo);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return i;
    }

    //Thêm chi tiết hóa đơn
    public static int themCTHoaDon(HoaDon hd) throws SQLException {
        int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(hd.maHoaDon);
            dsThamSo.add(hd.maThuoc);
            dsThamSo.add(hd.soLuong);

            i = KetNoiSQL.thucHienCapNhat("spThemCTHoaDon", dsThamSo);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return i;
    }

    //Xóa hóa đơn
    public static int xoaHoaDon(int maHoaDon) throws SQLException {
        int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(maHoaDon);
            i = KetNoiSQL.thucHienCapNhat("spXoaHoaDon", dsThamSo);
        } catch (SQLException sqlex) {
        }
        return i;
    }

    //Tìm kiếm
    public static Vector timKiem(String tenSP, Vector tkThuoc) throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan(tenSP, tkThuoc);
            while (rs.next()) {

                HoaDon xHD = new HoaDon();

                xHD.maHoaDon = rs.getInt(1);
                xHD.loaiHoaDon = rs.getString(2);
                xHD.tenKhachHang = rs.getString(3);
                xHD.tenThuoc = rs.getString(4);
                xHD.diaChi = rs.getString(5);
                xHD.ngayTao = rs.getString(6);
                xHD.thoiHan = rs.getString(7);
                xHD.thue = rs.getFloat(8);
                xHD.gia = rs.getFloat(9);
                xHD.tinhTrang = rs.getString(10);

                v.add(xHD);

            }

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return v;
    }
    
    //Tính tiền
    public static Vector tinhTien(String tenSP, Vector tinhTien) throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan(tenSP, tinhTien);
            while (rs.next()) {

                HoaDon xHD = new HoaDon();

                xHD.tien = rs.getInt(1);
                v.add(xHD);

            }

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return v;
    }
}
